﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

public static class common
{
	public static string StripTagsCharArray(string source)
	{
		if (source == null) return null;
		if (source.Length > 2048) source = source.Substring(0, 2048);
		source = source
			.Replace(".\r\n", ". \r\n")
			.Replace(".<br", ". <br")
			.Replace("</h1>", " [br] ")
			.Replace("</h2>", " [br] ")
			.Replace("</h3>", " [br] ")
			.Replace("</h4>", " [br] ")
			.Replace("</h5>", " [br] ")
			.Replace("</h6>", " [br] ")
			.Replace("</H1>", " [br] ")
			.Replace("</H2>", " [br] ")
			.Replace("</H3>", " [br] ")
			.Replace("</H4>", " [br] ")
			.Replace("</H5>", " [br] ")
			.Replace("</H6>", " [br] ");

		char[] array = new char[source.Length];
		int arrayIndex = 0;
		bool inside = false;

		for (int i = 0; i < source.Length; i++) {
			char let = source[i];
			if (source.Substring(i).ToLower().StartsWith("<br />")) {
				i += 6;
				array[arrayIndex] = '<';
				array[arrayIndex + 1] = 'b';
				array[arrayIndex + 2] = 'r';
				array[arrayIndex + 3] = ' ';
				array[arrayIndex + 4] = '/';
				array[arrayIndex + 5] = '>'; }

			if (let == '<') {
				inside = true;
				continue; }
			if (let == '>') {
				inside = false;
				continue; } 
			if (!inside) {
				array[arrayIndex] = let;
				arrayIndex++; } }
		return new string(array, 0, arrayIndex);
	}
}